
*Packages required
	ssc install spmap, replace

*Set working directory
	cd "/path/to/replication"

*Collapse database at the city level
	u "data/panel_month_dummies.dta", clear
	collapse (rawsum) n_hc asian_hc (firstnm) population, by(pro_com region city)
	
*Merge spatial file by city-code (pro_com)
	merge m:1 pro_com using "data/localita-11.dta", gen(m1)	
	tempfile full 
	save `full'
	
*Residually merge spatial file by city-name (region city)
	keep if m1==3
	tempfile matched
	save `matched'
	
	u `full'
	keep if m1==1 // master, hatecrimes
	drop id x_cc y_cc COD_REG COD_PRO pro_com 
	tempfile hatecrimes
	save `hatecrimes'
	
	u `full'
	keep if m1==2 // using, geo database
	keep id x_cc y_cc COD_REG COD_PRO pro_com city region 
	replace city=strupper(city)

	merge 1:m region city using `hatecrimes', gen(m2)
	drop if m2==1 // only in geo database
	
	append using `matched'
	
*Gen variables for map
	gen hc_pc=(n_hc/population)*10000
	gen hc_asian_d=1 if (asian_hc>0 & asian_hc!=.)
	
* MAP
	spmap hc_pc using "data/city-coord.dta", id(id) fcolor(Reds) ocolor(none none none none none none)  ///
			clmethod(custom) clbreaks(0 1 3 8 100) ///
			point( by(hc_asian_d) xcoord(x_cc) ycoord(y_cc) osize(*.5) size(*.5))  ///
			graphregion(color(white)) legend(off)
	
	graph export "map_hc_tot_asians.png", as(png) replace
